﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using BCCommon;
using BCDto.Common.News.NewsContentComment;
using BCService.Common.News.NewsContentCommentService;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace BCTMSRESTful.Controllers.Management.Common.News.NewsContentComment
{
    /// <summary>
    /// 新闻评论控制器
    /// </summary>
    [ApiExplorerSettings(GroupName = "Admin")]
    [Route("api/v1/sim/[controller]")]
    public class NewsContentCommentController : ManagementBaseController
    {
        private readonly INewsContentCommentService newsContentCommentService;
        /// <summary>
        /// 新闻评论控制器
        /// </summary>
        public NewsContentCommentController(INewsContentCommentService newsContentCommentService)
        {
            this.newsContentCommentService = newsContentCommentService;
        }
        /// <summary>
        /// 获取新闻内容评论列表（分页）仅获取顶级评论
        /// </summary>
        /// <param name="newsContentId">新闻Id</param>
        /// <param name="index">当前页</param>
        /// <param name="size">每页条数</param>
        /// <response code="200">带有分页信息的银行账户列表。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<NewsContentCommentDto>), 200)]
        public IActionResult Get([FromQuery(Name = "news_content_id")]long newsContentId, [FromQuery(Name = "index")]int? index = 1, [FromQuery(Name = "size")]int? size = 10)
        {
            return this.Ok(this.newsContentCommentService.GetList(newsContentId, index.Value, size.Value, null));
        }

        /// <summary>
        /// 获取一条新闻内容评论
        /// </summary>
        /// <param name="newsContentCommentId">新闻内容评论ID</param>
        /// <returns></returns>
        [HttpGet("{news_content_comment_id}")]
        [ProducesResponseType(typeof(NewsContentCommentDto), 200)]
        public IActionResult Get([FromRoute(Name = "news_content_comment_id")]long newsContentCommentId)
        {
            return this.Ok(this.newsContentCommentService.Get(newsContentCommentId));
        }

        /// <summary>
        /// 获取评论回复
        /// </summary>
        /// <param name="newsContentCommentId">新闻内容评论Id</param>
        /// <param name="newsContentId">新闻Id</param>        
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<NewsContentCommentDto>), 200)]
        public IActionResult GetChildrenList([FromQuery(Name = "news_content_comment_id")]long newsContentCommentId, [FromQuery(Name = "news_content_id")]long newsContentId,
             [FromQuery(Name = "index")]int? index = 1, [FromQuery(Name = "size")]int? size = 10)
        {
            return Ok(this.newsContentCommentService.GetChildrenCommentByCommentId(newsContentId, newsContentCommentId, index.Value, size.Value));
        }

        /// <summary>
        /// 获取所有新闻评论列表（分页）
        /// </summary>
        /// <param name="title">文章标题</param>
        /// <param name="comment">文章评论</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="ascending">排序</param>
        /// <param name="index">当前页</param>
        /// <param name="size">每页条数</param>
        /// <response code="200">带有分页信息的银行账户列表。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<NewsContentCommentDto>), 200)]
        public IActionResult Comments([FromQuery(Name = "title")]string title,
            [FromQuery(Name = "comment")]string comment,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int? index = 1,
            [FromQuery(Name = "size")]int? size = 10)
        {
            return this.Ok(this.newsContentCommentService.GetAllNewsContentCommentList(title, comment, start, end, ascending, index.Value, size.Value));
        }

        /// <summary>
        /// 删除一个新的新闻评论
        /// </summary>
        /// <returns></returns>
        /// <response code="204">刪除新闻评论成功。</response>
        [HttpDelete("{news_content_comment_id}")]
        [Log("删除新闻内容评论")]
        public IActionResult Delete([FromRoute(Name = "news_content_comment_id")]long newsContentCommentId)
        {
            this.newsContentCommentService.Delete(newsContentCommentId);
            return NoContent();
        }

        #region 启用/禁用新闻内容评论
        /// <summary>
        ///  启用/禁用新闻内容评论
        /// </summary>
        /// <param name="newsContentCommentId">新闻内容评论Id</param>
        /// <param name="enabled">是否启用</param>
        /// <response code="204">启用/禁用新闻内容评论成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("[action]/{news_content_comment_id}/{enabled}")]
        [Log("启用/禁用新闻内容评论")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Enabled([FromRoute(Name = "news_content_comment_id")]long newsContentCommentId,
            [FromRoute(Name = "enabled")]bool enabled)
        {
            if (enabled)
            {
                this.newsContentCommentService.Enabled(newsContentCommentId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
            else
            {
                this.newsContentCommentService.Disabled(newsContentCommentId);
                return StatusCode((int)HttpStatusCode.NoContent);
            }
        }
        #endregion
    }
}
